
#include "log.h"

 
static char *s_level_msg[] = {"SYS", "DEBUG", "ERROR", "WARNING", "MSG", "LOG"};
int js_log(const char *mod, const char *fmt, ...)
{
    va_list   args;
    va_start(args, fmt);
    js_vprint(LOG, mod, fmt, args);
    va_end(args);
    return 1;
}

int js_sys(const char *mod, const char *fmt, ...)
{
    va_list   args;
    va_start(args, fmt);
    js_vprint(SYS, mod, fmt, args);
    va_end(args);
    return 1;
}
int js_vprint(int level, const char *mod, const char *fmt, va_list ap)
{
    time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    
    char *level_msg = s_level_msg[level];
    char buf[1024];
    char *pbuf = buf;
    int ir = sprintf(pbuf, "[%d-%d-%d %d:%d:%d][%s][%s]", 
        tm->tm_year,
        tm->tm_mon,
        tm->tm_mday,
        tm->tm_hour,
        tm->tm_min,
        tm->tm_sec,
        level_msg, mod);
    
    pbuf += ir;
    vsprintf(pbuf, fmt, ap);
    
    printf(buf);
}
